# TurboWiki is a simple wiki module for TurboGears
#
# Copyright (C) 2009 Alberto Granzotto <agranzot@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import turbogears as tg
from turbogears import validators, widgets
from turbogears.database import session
from utils import wiki_validator 
__all__ = ['wiki_form']

langs = map(lambda x:x.strip(),
    tg.config.get('turbowiki.i18n.langs', 'en,it,fr,es,de').split(','))
def get_lang_options():
    #FIXME: i18n
    return ['en']
    return langs

        #############
        # Wiki Form #
        #############

class WikiFields(widgets.WidgetsList):
    #name = widgets.TextField('name',
    #    label=_('Page Name'), attrs={'disabled': 'true'})
    title = widgets.TextField('title', label=_('Page Title'),
        help_text=_('This will be the title of the web page.'))
    lang = widgets.SingleSelectField(label=_('Language'),
        options=get_lang_options)
    text = widgets.TextArea('text',
        label=_('Page Text'), attrs={'rows': '20', 'cols': '70'})
    preview = widgets.SubmitButton('preview',
        label=(''), attrs=dict(value=_('preview')))
    back = widgets.SubmitButton('back',
        label=(''), attrs=dict(value=_('back to the page')))

class WikiSchema(validators.Schema):
    name = wiki_validator
    title = validators.UnicodeString(not_empty=True, max=128, strip=True)
    lang = validators.String(not_empty=True, max=2, strip=True)
    text = validators.UnicodeString(not_empty=True)

wiki_form = widgets.TableForm(
    name="wiki_form",
    fields=WikiFields(),
    validator=WikiSchema())
